# Maintainer: fauxpark <fauxpark@gmail.com>

_realname=binutils
_target=avr

pkgbase=mingw-w64-${_target}-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_target}-${_realname}
pkgver=2.35
pkgrel=3
pkgdesc='GNU Binutils for the AVR target (mingw-w64)'
arch=('any')
license=('GPL')
url='https://www.gnu.org/software/binutils/binutils.html'
groups=("${MINGW_PACKAGE_PREFIX}-${_target}-toolchain")
source=(
    https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.xz{,.sig}
    "01-avr-size.patch"
)
sha256sums=(
    '1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85'
    'SKIP'
    '7aed303887a8541feba008943d0331dc95dd90a309575f81b7a195650e4cba1e'
)
validpgpkeys=('3A24BC1E8FB409FA9F14371813FCEF89DD9E3C4F')

prepare() {
    cd ${srcdir}/${_realname}-${pkgver}

    mkdir ${_realname}-build

    # https://github.com/archlinux/svntogit-community/blob/packages/avr-binutils/trunk/avr-size.patch
    patch -p1 -i ../01-avr-size.patch
}

build() {
    cd ${srcdir}/${_realname}-${pkgver}/${_realname}-build

    ../configure \
        --build=${MINGW_CHOST} \
        --prefix=${MINGW_PREFIX} \
        --target=${_target} \
        --disable-nls \
        --disable-debug \
        --disable-dependency-tracking \
        --disable-werror
    make
}

package() {
    cd ${srcdir}/${_realname}-${pkgver}/${_realname}-build

    make DESTDIR="$pkgdir" install

    cd ${pkgdir}${MINGW_PREFIX}

    for info in as bfd binutils gprof ld; do
        mv share/info/${info}.info share/info/${_target}-${info}.info
    done
}
